/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.chl.project.carshop07.core;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author AMADIN
 */
@XmlRootElement
@Entity
public class PurchaseOrder implements Serializable {
   
    
    private static final long serialVersionUID = 1L;
    @XmlAttribute
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date d8;
    
    @OneToMany ( cascade = { CascadeType.PERSIST, CascadeType.REMOVE },
    fetch = FetchType.EAGER)
    @JoinColumn
    private Collection<OrderItem> orderItems;
    
    
    @ManyToOne (cascade = { CascadeType.PERSIST})
    @JoinColumn
    private Customer customer;

    public PurchaseOrder() {
    }

    public PurchaseOrder(Customer customer, Collection<OrderItem> orderItems) {
        this.orderItems = orderItems;
        this.customer = customer;
    }

 
    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public Collection<OrderItem> getOrderItems() {
        return orderItems;
    }

    public void setOrderItems(Collection<OrderItem> orderItems) {
        this.orderItems = orderItems;
    }
    
    public Date getDate() {
        return d8;
    }

    public void setDate(Date d8) {
        this.d8 = d8;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PurchaseOrder)) {
            return false;
        }
        PurchaseOrder other = (PurchaseOrder) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "edu.chl.eghogho.PurchaseOrder[ id=" + id + " ]";
    }
    
}
